package com.ldw.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.ldw.mapper.ArticleMapper;
import com.ldw.pojo.Article;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
public class ThreadService {

    @Async("taskExecutor")
    public void updateArticlerViewCount(ArticleMapper articleMapper, Article article) {

        int viewCounts = article.getViewCounts();
        Article articleUpdate = new Article();
        articleUpdate.setViewCounts(viewCounts + 1);
        LambdaQueryWrapper<Article> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(Article::getId, article.getId());
        articleMapper.update(articleUpdate, queryWrapper);
        try {
            Thread.sleep(5000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
